class Solution {
    public int minSpeedOnTime(int[] dist, double hour) {
        int left = 1, right = (int) 1e7 + 1;
        if (dist.length - 1 >= hour) return -1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (check(dist, hour, mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }
    private boolean check(int[] dist, double hour, int v) {
        double time = 0;
        int n = dist.length;
        for (int i = 0; i < n - 1; i++) {
            time += Math.ceil(dist[i] * 1.0 / v);
        }
        time += dist[n - 1] * 1.0 / v;
        return time <= hour;
    }
}